package cn.springcloud.fix.es.web.controller;

import cn.springcloud.fix.es.web.request.AddCartRequest;
import cn.springcloud.fix.es.web.request.DeleteCartRequest;
import cn.springcloud.fix.es.web.request.UpdateCartRequest;
import cn.springcloud.fix.es.web.response.AddCartResponse;
import cn.springcloud.fix.es.web.response.DeleteCartResponse;
import cn.springcloud.fix.es.web.response.UpdateCartResponse;
import cn.springcloud.fix.es.web.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/cart")
public class CartController {

    @Autowired
    private CartService cartService;

    @PostMapping("/add")
    public AddCartResponse add(@Validated @RequestBody AddCartRequest request, HttpServletRequest httpServletRequest) {
        return cartService.add(request, httpServletRequest);
    }

    @PostMapping("/update")
    public UpdateCartResponse update(@Validated @RequestBody UpdateCartRequest request, HttpServletRequest httpServletRequest) {
        return cartService.update(request, httpServletRequest);
    }

    @PostMapping("/delete")
    public DeleteCartResponse delete(@Validated @RequestBody DeleteCartRequest request, HttpServletRequest httpServletRequest) {
        return cartService.delete(request, httpServletRequest);
    }
}
